import { defineStore } from "pinia";


export const useSysStore = defineStore("sys", {

    state: () => {
        return {
            collapsed: false,//默认菜单栏不收缩
            tags: [{
                path: '/home',
                name: 'home',
                label: '首页'
            }],//上方的tags标签数据
            spin:false
         
        }
    },
    getters: {

    },
    actions: {
        //添加标签
        addTag(value) {
            if (value.name !== 'home') {
                let index = this.tags.findIndex(item => item.name == value.name)
                index === -1 ? this.tags.push(value) : '';
            }
        },
        //删除标签
        removeTag(path) {
            let index = this.tags.findIndex(item => item.path ==path)
            this.tags.splice(index, 1)
        },
        openSpin() {
            this.spin = true
        },
        closeSpin() {
            this.spin = false
        },
    },

    persist:[
        {
            pick:['tags'],
            storage:sessionStorage,
        }
    ]
})